from openai import OpenAI

def load_api_key():
    try:
        with open("D:\\Documents\\deepseek_key.txt", "r") as f:
            return f.read().strip()
    except FileNotFoundError:
        print("警告：未找到 API key 文件，请确保文件存在于 D:\\Documents\\deepseek_key.txt")
        return ""

api_key = load_api_key()

# 初始化客户端
client = OpenAI(api_key=api_key, base_url="https://api.deepseek.com")

# 发送请求
response = client.chat.completions.create(
    model="deepseek-chat",
    messages=[
        {"role": "system", "content": "You are a helpful assistant"},
        {"role": "user", "content": "Hello"},
    ],
    stream=False
)

print(response.choices[0].message.content)
